'''
Created on 13-Jul-2010

@author: asa
'''
import time
import urlparse

class WebPage:
    def __init__(self, url):
        self.url = urlparse.urlparse(url)
        self.key = "webpage_" + url
        self.timestamp = time.time()
        self.comments = { }
        self.firstLevelComments = [ ]
        self.childToParentIndex = { }
        self.nextCommentId = 0
        
    def addComment(self, newComment):
        newComment.id = self.nextCommentId
        self.nextCommentId += 1
        self.comments[newComment.id] = newComment
        if newComment.parentId != -1:
            self.childToParentIndex[newComment.id] = newComment.parentId
        else:
            self.firstLevelComments.append(newComment)
    
    def getCommentsNumber(self):
        return len(self.comments)
    
    def __cmp__(self, o):
        if isinstance(o, WebPage):
            return self.url == o.url
        else:
            return False